<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
</head>

<body>
    <div id="wrap">
        {{name}}
        <hr>
        <first-cmp></first-cmp>
    </div>

    <!-- <my-component></my-component> -->

    <template id="demo1">
        <div>
            <h1>{{name}}</h1>
            <button @click="changeName">click me </button>
            <my-component></my-component>
        </div>
    </template>

    <template id="demo2">
        <div>
            <h1>{{name}}</h1>
            <button @click="changeName">click me </button>
        </div>
    </template>


</body>


<script>
    const myComponent = Vue.extend({
        template: '#demo2',
        data() {
            return {
                name: '这是一个局部组件'
            }
        },
        methods: {
            changeName() {
                this.name = '这还是一个局部组件'
            }
        }
    })


    Vue.component('FirstCmp', {
        template: '#demo1',
        data() {
            return {
                name: 'demo1'
            }
        },
        methods: {
            changeName() {
                this.name = 'no no demo1'
            }
        },
        //局部变量,需要引用才能使用
        components: {
            myComponent,
        }
    })

    new Vue({ el: '#wrap', data: { name: 'Hello!' } })
</script>

</html>